package com.changgou.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
public class UrlFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //获取客户端的访问路径
        System.out.println("执行了返回优先权为2的过滤器");
        ServerHttpRequest request = exchange.getRequest();
        System.out.println("URI"+request.getURI()); // URI http://localhost:9101/brand/category/%E6%89%8B%E6%9C%BA
        String path = request.getURI().getPath(); //获取到URI后获取路径 path/brand/category/手机
        System.out.println("path" + path);
        //放行
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 2;
    }
}
